package org.jetlinks.community.messaging.rabbitmq.command.admin;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.jetlinks.community.datasource.Command;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

@Getter
@Setter
@AllArgsConstructor
public class GetPermissions extends AdminCommand<Flux<Permission>> {

    private String username;

    @Override
    public String api() {
        return "/api/users/" + username + "/permissions";
    }

    @Override
    public HttpMethod method() {
        return HttpMethod.GET;
    }

    @Override
    public Flux<Permission> convert(WebClient.ResponseSpec responseSpec) {
        return responseSpec
            .bodyToFlux(Permission.class)
            .doOnNext(per -> per.setUsername(username));
    }
}
